package cn.maxhou.controller;

import jakarta.servlet.http.HttpServletRequest;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

/**
 * 使用注解时,Controller类型也可以是普通类型
 * 但是需要标注@Controller注解
 */
@Controller
public class HelloController5 {
    private static final Logger LOGGER= LoggerFactory.getLogger(HelloController5.class);
    /**
     * 使用注解时,控制器方法是一个普通方法
     * 由@RequestMapping注解映射请求路径
     */
    @RequestMapping("/hello2")
    protected String hello(@RequestParam(value="name") String name) {
        LOGGER.info("你好{},欢迎学习SpringMVC!",name);
        //调转到 /WEB-INF/jsp/hello.jsp
        return "hello";
    }

    //定义入参参数,required默认为true表示必填,设置为false,则为非必填
    @RequestMapping("/hello3")
    protected String hello2(@RequestParam(value="name",required = false) String name) {
        LOGGER.info("你好{},欢迎学习SpringMVC!",name);
        //调转到 /WEB-INF/jsp/hello.jsp
        return "hello";
    }

    @RequestMapping("/hello5")
    protected String hello3(@RequestParam(value="realName",required = false) String name) {
        LOGGER.info("你好{},欢迎学习SpringMVC!",name);
        //调转到 /WEB-INF/jsp/hello.jsp
        return "hello";
    }
}
